<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <div class="app-space-between">
        <div class="app-space-between-left">
          <el-form-item label="优惠券名称:" prop="couponName">
            <el-input v-model="queryParams.couponName" placeholder="请输入优惠券名称" clearable @clear="handleQuery"
              @keyup.enter.native="handleQuery" />
          </el-form-item>
          <el-form-item label="状态:" prop="couponState">
            <el-select v-model="queryParams.couponState" clearable placeholder="请选择商品分类" @change="handleQuery">
                <el-option label="预置" value="预置" />
                <el-option label="发布" value="发布" />
                <el-option label="失效" value="失效" />
                <el-option label="取消" value="取消" />
            </el-select>
          </el-form-item>
        </div>
        <div class="app-space-between-right">
          <el-form-item>
            <el-button type="primary" size="mini" @click="handleQuery">搜索</el-button>
            <el-button size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </div>
      </div>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleExport">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="postList">
      <el-table-column label="优惠券名称" align="center" prop="couponName" />
      <el-table-column label="面值（元）" align="center" prop="couponValue" />
      <el-table-column label="类型" align="center" prop="couponType" />
      <el-table-column label="有效期" align="center">
        <template slot-scope="scope">
          <div>{{scope.row.validiteStart}} 至 {{scope.row.validiteEnd}}</div>
        </template>
      </el-table-column>
      <el-table-column label="最低消费额度（元）" align="center" prop="minMonetary" />
      <el-table-column label="状态" align="center" prop="couponState" />
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
  import {
    couponList,
    couponAdd,
    couponDelete,
    couponDetails,
    couponEdit,
    couponExport
  } from "@/api/coupon/content"
  import {commonDownload} from "@/api/common.js"
  export default {
    data() {
      return {
        onSubmitDis: false,
        showEdit: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 岗位表格数据
        postList: [],
        // 弹出层标题
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          couponName: undefined,
          couponState: undefined
        },
        // 表单参数
     };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询岗位列表 */
      getList() {
        this.loading = true;
        couponList(this.queryParams).then(response => {
          this.postList = response.rows;
          this.total = response.total;
          this.loading = false;
        });

      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 导出按钮操作 */
      handleExport() {
        couponExport().then(res=>{
          console.log('下载信息',res.msg)
          commonDownload({
            fileName:res.msg,
            delete: false
          }).then(res=>{
              console.log('下载的内容',res)
          })
        })
      }
    }
  };
</script>
